package user;

import java.io.File;

import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;

import utils.FileUtil;
import dao.Jdbcuserdao;
import dao.Userdao;

public class UPloadAction {
	private int id;
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	private File mf;//客户上传的临时文件对象
	private String mfFileName;//原文件名 
	private String mfContentType;//获取文件MIME类型
	
	public String execute(){
		//将mf复制到工程的upload目录下
		System.out.println(mf.getPath());
		
		System.out.println(mfFileName);
		
		
		System.out.println(mfContentType);
		ServletContext application = ServletActionContext.getServletContext();
		String realPath = application.getRealPath("upload/");
		
		String filePath = realPath + File.separatorChar + mfFileName;
		System.out.println(filePath);
		try {
			FileUtil.copy(mf, new File(filePath));
			Userdao dao=new Jdbcuserdao();
			dao.image(filePath, id);
			return "success";
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
	}

	

	
	
	public File getMf() {
		return mf;
	}

	public void setMf(File mf) {
		this.mf = mf;
	}

	public String getMfFileName() {
		return mfFileName;
	}

	public void setMfFileName(String mfFileName) {
		this.mfFileName = mfFileName;
	}

	public String getMfContentType() {
		return mfContentType;
	}

	public void setMfContentType(String mfContentType) {
		this.mfContentType = mfContentType;
	}
}
